import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @Author @fiber-cloud
 * @Date 2025/10/29 11:37
 */

class Student{
    public int classId;
    public int studentId;
}

public class TeskJackson {
    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
//        //readValue是把json格式的字符串转成Java对象
//        String s = "{\"classId\":10,\"studentId\":20}" ;
//        //readValue第一个参数可以直接写个String，也可以写成InputStream
//        Student student = objectMapper.readValue(s,Student.class);
//
//        System.out.println(student.classId);
//        System.out.println(student.studentId);


        //Java对象转成json格式
        Student student = new Student();
        student.classId = 10;
        student.studentId = 20;

        String s =objectMapper.writeValueAsString(student);

        System.out.println(s);
    }
}
